import zmail
from config.conf import cm
# import datetime
import time
from common.basePage import email_info
import shutil
import os
from config.conf import ConfigManager


def send_report():
    # 发送报告

    # if os.path.exists(ConfigManager.BASE_DIR+'reports'):
    # shutil.make_archive(ConfigManager.BASE_DIR+'\\allure-report', 'zip', ConfigManager.BASE_DIR+'\\reports')

    # current_time = datetime.datetime.now()
    current_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
    with open(cm.REPORT_FILE, encoding='gbk') as f:
        content_html = f.read()

    try:
        mail = {
            'from': '39560610@qq.com',
            # 'subject': '测试报告',
            'subject': '测试报告-日期 ' + str(current_time),
            'content_html': content_html,
            'attachments': [cm.REPORT_FILE]
        }
        server = zmail.server(*email_info().values())
        server.send_mail(cm.ADDRESSER, mail)
        print('邮件发送成功！')
    except Exception as e:
        print('出错，邮件未能发送，{}！'.format(e))


# if __name__ == '__main__':
#     send_report()

